#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

const int inf = INT_MAX / 3;
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> v(n + 1), c(n + 1), sum(n + 1);
  for (int i = 1; i <= n; i ++) cin >> v[i];
  for (int i = 1; i <= n; i ++) cin >> c[i];
  partial_sum(v.begin(), v.end(), sum.begin());

  vector<vector<array<int, 3>>> dp(n + 1, vector<array<int, 3>>(n + 1));
  for (int l = n; l >= 1; l --) {
    dp[l][l] = {inf, inf, inf};
    dp[l][l][c[l]] = 0;
    for (int r = l + 1; r <= n; r ++) {
      dp[l][r] = {inf, inf, inf};
      for (int k = l; k < r; k ++) {
        for (int c = 0; c < 3; c ++) {
          if (dp[l][k][c] == inf || dp[k + 1][r][c] == inf) continue;
          int nc = (c + 1) % 3;
          dp[l][r][nc] = min(dp[l][r][nc], dp[l][k][c] + dp[k + 1][r][c] + sum[r] - sum[l - 1]);
        }
      }
    }
  }
  vector<pair<int, int>> linear(n + 1, {inf, 0});
  linear[0] = {0, 0};
  for (int i = 1; i <= n; i ++) {
    for (int j = 1; j <= i; j ++) {
      for (int c = 0; c < 3; c ++) {
        if (dp[j][i][c] == inf) continue;
        linear[i] = min(linear[i], {linear[j - 1].first + 1, linear[j - 1].second + dp[j][i][c]});
      }
    }
  }
  cout << linear[n].first << ' ' << linear[n].second << '\n';
}